package com.example.myjavafx.controller;

import javafx.fxml.FXML;
import javafx.scene.SubScene;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Group;
import javafx.scene.shape.Box;

/**
 * @author admin
 */
public class GraphicsController {

    @FXML
    private ToggleButton mode2DButton;

    @FXML
    private ToggleButton mode3DButton;

    @FXML
    private Pane view2D;

    @FXML
    private StackPane view3DContainer;

    @FXML
    private SubScene view3D;

    @FXML
    private void initialize() {
        setupView2D();
        setupView3D();
    }

    @FXML
    private void switchTo2D() {
        view2D.setVisible(true);
        view2D.setManaged(true);
        view3DContainer.setVisible(false);
        view3DContainer.setManaged(false);
        mode2DButton.setSelected(true);
        mode3DButton.setSelected(false);
    }

    @FXML
    private void switchTo3D() {
        view2D.setVisible(false);
        view2D.setManaged(false);
        view3DContainer.setVisible(true);
        view3DContainer.setManaged(true);
        mode2DButton.setSelected(false);
        mode3DButton.setSelected(true);
    }

    private void setupView2D() {
        Rectangle rectangle = new Rectangle(100, 100, 200, 150);
        rectangle.setFill(Color.BLUE);

        Circle circle = new Circle(300, 200, 50);
        circle.setFill(Color.RED);

        view2D.getChildren().addAll(rectangle, circle);
    }

    private void setupView3D() {
        Group root3D = new Group();
        Box box = new Box(100, 100, 100);
        box.setTranslateX(250);
        box.setTranslateY(150);
        box.setTranslateZ(0);

        root3D.getChildren().add(box);

        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.setTranslateZ(-500);

        view3D.setRoot(root3D);
        view3D.setCamera(camera);
    }
}
